﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Models;
using BLL;

namespace Dryricenet.houTai
{
    public partial class Backstage : System.Web.UI.Page
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                this.Page.Form.DefaultButton = "Button1";
                //Xlk();
            }
        }
        //下拉框
        //public void Xlk()
        //{
        //    DropDownList1.DataSource = userType.liXlkBLL();
        //    DropDownList1.DataTextField = "Name";
        //    DropDownList1.DataValueField = "TypeID";
        //    DropDownList1.DataBind();
        //}
        protected void Button1_Click(object sender, EventArgs e)
        {
            string yzm = Session["yzm"].ToString();
            string name = txtName.Text.Trim();
            string pwd = txtPwd.Text.Trim();
            
            if (txtName.Text.Trim()!="")
            {
                if (txtPwd.Text.Trim() != "")
                {
                    if (TextBox1.Text.Trim() != "")
                    {
                        if (TextBox1.Text.Trim().ToLower() == yzm.ToLower())
                        {

                           
                               
                                if (Convert.ToInt32(userBLL.userGLBLL(name))==2)
                                {
                                    if (userBLL.loginBll(name, pwd).Rows.Count > 0)
                                    {
                                        Session["UserName"] = name;
                                        Session["UserPwd"] = pwd;
                                        Response.Redirect("Management.aspx");
                                    }
                                    else
                                    {
                                        Response.Write("<script>javascript:alert('亲,登录失败了哦!');history.back();</script>");
                                        Response.End();
                                    }
                                }
                                else
                                {
                                    Response.Write("<script>javascript:alert('您不是管理员无法登录！');history.back();</script>");
                                    Response.End();
                                }

                           
                            
                        }
                        else {
                            Response.Write("<script>alert('验证码输入不正确！')</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('请输入验证码！')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('请输入密码！')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('请输入用户名！')</script>");
            }
            
        }
    }
}